import java.util.Arrays;

public class Task {

    public static void main8(String[] args) {
        //8.存在连续三个奇数的数组
        int[] arr = {1,5,2,4,3,5,7,6};
        boolean bool = ifOdd(arr);
        System.out.println(bool);
    }
    public static boolean ifOdd(int[] arr) {
        int count = 0;
        for (int i = 0; i < arr.length; i++) {
            if(count==3) {
                return true;
            }
            if(arr[i]%2!=0) {
                count++;
            } else {
                count=0;
            }
        }
            return false;
    }
    public static void main7(String[] args) {
        //7.给定一个大小为 n 的数组，找到其中的多数元素,大于n/2的元素，如：6/2=3次，7/2=3，8/2=4
        int[] arr ={1,2,1,2,2,3};
        int num = (int) (arr.length/2);
        for (int i = 1; i < arr.length; i++) {
            int count = 1;
            for (int j = 1; j < arr.length; j++) {
                if(arr[0]==arr[j]) {
                    count++;
                }
            }
            if(count==num) {
                System.out.println(arr[0]);
                break;
            }
            int tmp = arr[i];
            arr[i] = arr[0];
            arr[0] = tmp;

        }

    }
    public static void main6(String[] args) {
        //6.找出那个只出现了一次的元素。
        int[] arr = {1,2,2,3,3,4,4};
        int ret = 0;
        for (int i = 0; i < arr.length; i++) {
            ret^=arr[i];
        }
        System.out.println(ret);
    }
    public static void main5(String[] args) {
        //5.求哪两个数组之和=目标，输出其下标
        int[] nums = {1,2,3,4,5,6,7,8,9,10};
        int target = 12;
        int[] ret = Nums(nums,target);
        System.out.println(Arrays.toString(ret));
    }
    public static int[] Nums(int[] nums,int target) {

        for (int i = 0; i < nums.length-1; i++) {
            for (int j = 1+i; j <nums.length ; j++) {
                if(nums[i]+nums[j]==target) {
                   int[] array = new int[]{i,j};
                    return array;
                }
            }
        }
        return null;
    }
    public static void main(String[] args) {
        //4.调整数组顺序使得奇数位于偶数之前
        int[] arr = {1,1,1,1,1,1,3,5};
        oddarr(arr);
        System.out.println(Arrays.toString(arr));
    }
    public static void oddarr(int[] arr) {
        int left = 0;
        int right = arr.length-1;
        while(left<right) {
            if(arr[left]%2==0) {
                int tmp = arr[left];
                arr[left] = arr[right];
                arr[right] = tmp;
                right--;
            } else {
                left++;
            }
        }
    }
    public static void main3(String[] args) {
        //3.实现一个方法 sum, 以数组为参数, 求数组所有元素之和.
        int[] arr = {1,2,3,4,5};
        int Sum = sum(arr);
        System.out.println(Sum);
    }
    public static int sum(int[] arr) {
        int sum = 0;
        for (int i = 0; i < arr.length; i++) {
            sum+=arr[i];
        }
        return sum;
    }
    public static void main2(String[] args) {
        //2.实现一个方法 transform,数组数据*2
        int[] arr = {1,2,3,4,5};
        transform(arr);
        System.out.println(Arrays.toString(arr));
    }
    public static void transform(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            arr[i]*=2;
        }
    }
}
